package com.ldzy.interceptor;


import com.ldzy.pojo.User;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class LoginInterceptor extends HandlerInterceptorAdapter {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session=request.getSession();
        System.out.println(123);
        User user=(User) session.getAttribute("user");
        if(user!=null){
            return true;
        }
        //返回为假
        request.setAttribute("msg","你还没有登录！");
        request.getRequestDispatcher("/admin/login.jsp").forward(request,response);
        return false;
    }
}
